Because the effect will be directly executed, the effect description is not added to a video track, as described in "Adding the Effect Description to the Track." Instead, a decompression sequence is created which will execute the effect. The sample, and its description, form part of the input to the decompression sequence. For complete details of setting up and using decompression sequences, see Chapter 4, "Image Compressor Components."
The code shown in Listing 20-9 prepares a decompression sequence for playback, given the effect description in myEffectDesc and the sample description in mySampleDesc . The function generates a sequence identifier, which in this example is stored in the variable gEffectSequenceID . The variable mainWindow contains the display surface on which the effect will be shown. In this case, it is the application's main window. Full details of this call are provided in Chapter 3, "Image Compression Manager."
Listing 9 Preparing a decompression sequence used to execute an effect directly
HLock((Handle) myEffectDescription);
DecompressSequenceBeginS(&gEffectSequenceID,
mySampleDescription,
StripAddress(*myEffectDescription),
GetHandleSize(myEffectDescription),
(CGrafPtr) mainWindow,
NULL,
NULL,
NULL,
ditherCopy,
NULL,
0,
codecNormalQuality,
NULL);
HUnlock((Handle) myEffectDescription);
The value passed in the accuracy field to this call (in this example the value is codecNormalQuality ) controls how the effect component optimizes the rendering of the effect. Values less than or equal to codecNormalQuality indicate that the decompression sequence should be executed in near real-time effect. This means that the visual quality of the effect may be compromised in order to achieve high-speed playback.
A setting of codecHighQuality indicates to the component that it should not attempt to sacrifice quality of the rendering for speed of playback, and should instead render the effect with maximum visual quality. This is particularly useful when the effect is being used to process images off-line.
Once the decompression sequence is set up, the sources for the effect must be associated with the source names used in the effect description. When you are creating a QuickTime movie containing effects, the input map provides this association. When an effect is being directly executed, use the functions CDSequenceNewDataSource and CDSequenceSetSourceData to create the named sources.
The code in Listing 20-10 shows how image descriptions for a GWorld ( gWorld1 ) are generated by calling MakeImageDescriptionForPixMap . The image description is then named srcA using the CDSequenceNewDataSource function.
Listing 10 Generating image descriptions for a GWorld
{
ImageSequenceDataSourcemySrc1 = 0;
// Generate a description of the first GWorld and store it in gWorld1Desc
myErr = MakeImageDescriptionForPixMap(gWorld1->portPixMap, &gWorld1Desc);
// Create a source from the GWorld description.
myErr = CDSequenceNewDataSource(gEffectSequenceID,
&mySrc1,
`srcA',
1,
(Handle)gWorld1Desc,
NULL,
0);
// Set the data for source srcA to be the pixMap of the GWorld gWorld1
CDSequenceSetSourceData(mySrc1,
GetPixBaseAddr(gWorld1->portPixMap),
(**gWorld1Desc).dataSize);
}
The last step in preparing the decompression sequence is to create a time base which will be used in the playback of the effect.
The code in Listing 20-11 creates a new time base and sets its rate to 0 . The new time base is then associated with the newly created decompression sequence.
The time base's rate is set to 0 because the effect is being played outside the context of a QuickTime movie. This means your application must repeatedly call the RunEffect function (described below) to playback the effect, instead of relying on QuickTime to honor the time base rate.
Listing 11 Adding a time base to a decompression sequence
gTimeBase = NewTimeBase();
SetTimeBaseRate(gTimeBase, 0);
CDSequenceSetTimeBase(gEffectSequenceID, gTimeBase);
| Previous | Chapter contents | Chapter top | Section top | Next |